﻿using System;
using System.IO;
using System.Windows;
using Serietheque.Properties;
using System.Windows.Media;
using System.Windows.Controls;

/* MAJ XML et deux trois truc a faire */

namespace Serietheque.Fenetres
{
    /// <summary>
    /// Logique d'interaction pour Preference.xaml
    /// </summary>
    public partial class Preference : Window
    {
        private bool m_consolidation = false;

        public bool Consolidation
        {
            get { return m_consolidation; }
            set { m_consolidation = value; }
        }

        public bool PathUpdated { get; set; }

        public Preference()
        {
            InitializeComponent();
        }


        private void parcourir_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();

            StackPanel parent = Extension.TryFindParent<StackPanel>(sender as Button);

             dlg.Description = "Sélectionner un dossier";
            

            if (parent.Name == "Serie")
            {               
                if (Directory.Exists(Settings.Default.Serie))
                    dlg.SelectedPath = Settings.Default.Serie;
                else
                    dlg.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Settings.Default.Serie = dlg.SelectedPath;
                    PathUpdated = true;
                }
                else
                    System.Windows.Forms.MessageBox.Show("Choisissez un dossier");
            }
            else if (parent.Name == "SerieDl")
            {
                if (Directory.Exists(Settings.Default.SerieDl))
                    dlg.SelectedPath = Settings.Default.SerieDl;
                else
                    dlg.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);


                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Settings.Default.SerieDl = dlg.SelectedPath;
                    PathUpdated = true;
                }
                else
                    System.Windows.Forms.MessageBox.Show("Choisissez un dossier");
            }
            else if (parent.Name == "SubDl")
            {
                if (Directory.Exists(Settings.Default.SubDl))
                    dlg.SelectedPath = Settings.Default.SubDl;
                else
                    dlg.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);


                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Settings.Default.SubDl = dlg.SelectedPath;
                    PathUpdated = true;
                }
                else
                    System.Windows.Forms.MessageBox.Show("Choisissez un dossier");
            }
            else if (parent.Name == "Cache")
            {
                if (Directory.Exists(Settings.Default.Cache))
                    dlg.SelectedPath = Settings.Default.Cache;
                else
                    dlg.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);


                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Settings.Default.Cache = dlg.SelectedPath;
                    PathUpdated = true;
                }
                else
                    System.Windows.Forms.MessageBox.Show("Choisissez un dossier");
            }
        }
        
        private void ok_Click(object sender, RoutedEventArgs e)
        {
            Settings.Default.Save();
            this.DialogResult = true;
            Close();
        }

        private void consolidationBtn_Click(object sender, RoutedEventArgs e)
        {
            m_consolidation = true;
            Close();
        }


    }
}